/*
  学习目标：类型断言 - 又叫, "听哥的" 或 "听我的"
  作用: 告诉TS，以我的类型为准
  场景: TS推断不准确时使用
  语法:   = 值 as 类型
*/

type Profile = {
  name: string;
  avatar: string;
  token: string;
};

// let profile = {}; ❌ TS无法推断出 profile是 Profile类型
// profile.name = "zs" ❌
let profile = {} as Profile;
profile.name = "zs";

type Person = {
  name: string;
  age: number;
  gender?: string;
};
// const zs = { name: 'zs', age: 18 } ❌ TS无法推断出 zs 是 Person类型
// zs.gender = 'xxx' ❌

const zs = { name: "zs", age: 18 } as Person; // ✅
zs.gender = "xxx"; // ✅
